import store from '@/store'
const hashasPermission = (el, binding) => {
  const { value } = binding
  if (value && value instanceof Array) {
    const permissionRoles = value
    const roleList = store.getters.userInfo.permission.points
    const hasPermission = () => {
      return roleList.some((role) => {
        return permissionRoles.includes(role)
      })
    }
    if (!hasPermission(permissionRoles)) {
      el.parentNode && el.parentNode.removeChild(el)
    }
  } else {
    throw new Error('need roles! Like v-permission="["admin","editor"]"')
  }
}
export default {
  mounted(el, binding) {
    hashasPermission(el, binding)
  },
  beforeMount(el, binding) {
    hashasPermission(el, binding)
  }
}
